<?php namespace Common\Model;
use Hdphp\Model\Model;
/**
 * 标签表模型
 */
class Tag extends Model{
	//标签表
	protected $table = 'tag';
	//自动验证(前提：表字段必须和表单一致)
	protected $validate = array(
			array('tname','required','标签名称必须填写哦^_^',3,3),
			array('tname','maxlen:10','标签名称不能超过10个字符哦^_^',3,3)
	);
	
	
	//添加
	public function addTag($tname){
			//如果验证通过,执行添加操作
			if ($this->create()) {
					$tnameArr = explode("|", $tname);
					//循环  添加多条
					foreach ($tnameArr as $tname){
							$this->add(array('tname' =>$tname));
					}
					return true;
			}
			//否则验证失败
			return false;
	}
	
	//修改
	public function edit($tid){
			//触发自动验证,验证通过执行修改
			if ($this->create()) {
					$this->where(array('tid' => $tid))->save();
					return true;
			}
			//验证失败,返回false 错误提示
			return false;
	}
	
}
?>